package com.warrantyhotel.android.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.ImageView;

public class CustomImageView extends ImageView {
	private Activity context;

	public CustomImageView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.context = (Activity) context;
	}

	public CustomImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = (Activity) context;
	}

	public CustomImageView(Context context) {
		super(context);
		this.context = (Activity) context;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		float radius = 15.0f;

		DisplayMetrics metrics = new DisplayMetrics();
		context.getWindowManager().getDefaultDisplay().getMetrics(metrics);

		switch (metrics.densityDpi) {
		case DisplayMetrics.DENSITY_MEDIUM:
			radius = 15.0f;
			break;
		case DisplayMetrics.DENSITY_HIGH:
			radius = 30.0f;
			break;
		}

		Path clipPath = new Path();
		RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight());
		clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW);
		canvas.clipPath(clipPath);

		super.onDraw(canvas);
	}

}
